package com.androway.domains;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.google.gson.annotations.Expose;

public class User extends AbstractPersistentObject
{
	public static final int		PROMO_MIN			= 2002;
	public static final int		PROMO_NONE			= -1;

	public static final String	TYPE_TIGABLE		= "TIGABLE";
	public static final String	TYPE_FOLLOWABLE		= "FOLLOWABLE";
	public static final String	TYPE_REGISTRABLE	= "REGISTRABLE";
	public static final String	TYPE_TEACHER		= "TEACHER";
	public static final String	TYPE_AER			= "AER";

	@Expose
	private String				firstname			= null;
	@Expose
	private String				lastname			= null;
	@Expose
	private String				alias				= null;
	@Expose
	private Date				birthday			= null;
	@Expose
	private int					promo;
	@Expose
	private String				login				= null;
	private String				password			= null;
	@Expose
	private String				email				= null;
	@Expose
	private Set<Group>			groupList			= new HashSet<Group>();
	@Expose
	private Set<Job>			jobList				= new HashSet<Job>();
	@Expose
	private int					color				= -1;
	private String				md5password			= null;
	private Date				lastConnection		= null;
	private School				school				= null;

	public boolean hasPermission(String name, int value)
	{
		for (Group group : this.groupList)
			if (group.hasPermission(name, value))
				return true;
		return false;
	}

	public int getHigherGroupLevel()
	{
		int higherLevel = Group.LEVEL_NONE;
		int groupLevel;
		for (Group group : this.groupList)
		{
			groupLevel = group.getHigherLevel();
			if (groupLevel > higherLevel)
			{
				if (groupLevel == Group.LEVEL_GOD)
					return groupLevel;
				higherLevel = groupLevel;
			}
		}
		return higherLevel;
	}

	public String getFirstname()
	{
		return this.firstname;
	}

	public void setFirstname(String firstname)
	{
		this.firstname = firstname;
	}

	public String getLastname()
	{
		return this.lastname;
	}

	public void setLastname(String lastname)
	{
		this.lastname = lastname;
	}

	public String getAlias()
	{
		return this.alias;
	}

	public void setAlias(String alias)
	{
		this.alias = alias;
	}

	public Date getBirthday()
	{
		return this.birthday;
	}

	public void setBirthday(Date birthday)
	{
		this.birthday = birthday;
	}

	public int getPromo()
	{
		return this.promo;
	}

	public void setPromo(int promo)
	{
		this.promo = promo;
	}

	public String getLogin()
	{
		return this.login;
	}

	public void setLogin(String login)
	{
		this.login = login;
	}

	public String getPassword()
	{
		return this.password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getEmail()
	{
		return this.email;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	public Set<Group> getGroupList()
	{
		return this.groupList;
	}

	public void setGroupList(Set<Group> groupList)
	{
		this.groupList = groupList;
	}

	public Set<Job> getJobList()
	{
		return this.jobList;
	}

	public void setJobList(Set<Job> jobList)
	{
		this.jobList = jobList;
	}

	public Integer getColor()
	{
		return this.color;
	}

	public void setColor(Integer color)
	{
		this.color = color;
	}

	public School getSchool()
	{
		return this.school;
	}

	public void setSchool(School school)
	{
		this.school = school;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return this.getLogin() + " (" + this.getUid() + ")";
	}

	public String getMd5password()
	{
		return md5password;
	}

	public void setMd5password(String md5password)
	{
		this.md5password = md5password;
	}

	public Date getLastConnection()
	{
		return lastConnection;
	}

	public void setLastConnection(Date lastConnection)
	{
		this.lastConnection = lastConnection;
	}
}
